<template>


  <div  class="m-container m-padded-tb-big animated fadeIn">
    <div class="ui container">
      <div class="ui stackable grid">
        <!--左边博客列表-->
        <div class="eleven wide column">
          <!--header-->
          <div class="ui top attached segment">
            <div class="ui middle aligned two column grid">
              <div class="column">
                <h3 class="ui teal header">博客</h3>
              </div>
              <div class="right aligned column">
                共 <h2 class="ui orange header m-inline-block m-text-thin"> {{blogCount}} </h2> 篇
              </div>
            </div>
          </div>

          <!--content-->
          <div class="ui attached  segment">

            <div class="ui padded vertical segment m-padded-tb-large" v-for="blog in blogs">
              <div class="ui middle aligned mobile reversed stackable grid" >
                <div class="eleven wide column">
                  <h3 class="ui header" ><a style="cursor:pointer" @click="toBlog(blog.id)" target="_blank" class="m-black">{{blog.title}}</a></h3>
                  <p class="m-text">{{blog.description}}</p>
                  <div class="ui grid">
                    <div class="eleven wide column">
                      <div class="ui mini horizontal link list">
                        <div class="item">
                          <img :src="blog.user.avatar" alt="" class="ui avatar image">
                          <div class="content"><a href="#" class="header">{{blog.user.nickname}}</a></div>
                        </div>
                        <div class="item">
                          <i class="calendar icon"></i><span>{{dateFormat(blog.updateTime)}}</span>
                        </div>
                        <div class="item">
                          <i class="eye icon"></i> <span>{{blog.views}}</span>
                        </div>
                      </div>
                    </div>
                    <div class="right aligned five wide column">
                      <a style="cursor: pointer" @click="toType(blog.type.id)" target="_blank" class="ui teal basic label m-padded-tiny m-text-thin">{{blog.type.name}}</a>
                    </div>
                  </div>
                </div>

                <div class="five wide column">
                  <a style="cursor:pointer" @click="toBlog(blog.id)" target="_blank">
                    <img :src="blog.firstPicture" alt="" class="ui rounded image">
                  </a>
                </div>

              </div>
            </div>
            <!--/*-->
<!--            <div class="ui padded vertical segment m-padded-tb-large">-->
<!--              <div class="ui mobile reversed stackable grid">-->
<!--                <div class="eleven wide column">-->
<!--                  <h3 class="ui header">你真的理解什么是财富自由吗？</h3>-->
<!--                  <p class="m-text">正确做好任何一件事情的前提是清晰、正确的理解目标。而事实是，我们很多人很多时候根本没有对目标正确的定义，甚至根本从来就没有想过，只是大家都那么做而已…...</p>-->
<!--                  <div class="ui grid">-->
<!--                    <div class="eleven wide column">-->
<!--                      <div class="ui mini horizontal link list">-->
<!--                        <div class="item">-->
<!--                          <img src="https://unsplash.it/100/100?image=1005" alt="" class="ui avatar image">-->
<!--                          <div class="content"><a href="#" class="header">刘汉东</a></div>-->
<!--                        </div>-->
<!--                        <div class="item">-->
<!--                          <i class="calendar icon"></i> 2017-10-01-->
<!--                        </div>-->
<!--                        <div class="item">-->
<!--                          <i class="eye icon"></i> 2342-->
<!--                        </div>-->
<!--                      </div>-->
<!--                    </div>-->
<!--                    <div class="right aligned five wide column">-->
<!--                      <a href="#" target="_blank" class="ui teal basic label m-padded-tiny m-text-thin">认知升级</a>-->
<!--                    </div>-->
<!--                  </div>-->
<!--                </div>-->

<!--                <div class="five wide column">-->
<!--                  <a href="#" target="_blank">-->
<!--                    <img src="https://unsplash.it/800/450?image=1005" alt="" class="ui rounded image">-->
<!--                  </a>-->
<!--                </div>-->

<!--              </div>-->
<!--            </div>-->
<!--            <div class="ui padded vertical segment m-padded-tb-large">-->
<!--              <div class="ui mobile reversed stackable grid">-->
<!--                <div class="eleven wide column">-->
<!--                  <h3 class="ui header">你真的理解什么是财富自由吗？</h3>-->
<!--                  <p class="m-text">正确做好任何一件事情的前提是清晰、正确的理解目标。而事实是，我们很多人很多时候根本没有对目标正确的定义，甚至根本从来就没有想过，只是大家都那么做而已…...</p>-->
<!--                  <div class="ui grid">-->
<!--                    <div class="eleven wide column">-->
<!--                      <div class="ui mini horizontal link list">-->
<!--                        <div class="item">-->
<!--                          <img src="https://unsplash.it/100/100?image=1005" alt="" class="ui avatar image">-->
<!--                          <div class="content"><a href="#" class="header">刘汉东</a></div>-->
<!--                        </div>-->
<!--                        <div class="item">-->
<!--                          <i class="calendar icon"></i> 2017-10-01-->
<!--                        </div>-->
<!--                        <div class="item">-->
<!--                          <i class="eye icon"></i> 2342-->
<!--                        </div>-->
<!--                      </div>-->
<!--                    </div>-->
<!--                    <div class="right aligned five wide column">-->
<!--                      <a href="#" target="_blank" class="ui teal basic label m-padded-tiny m-text-thin">认知升级</a>-->
<!--                    </div>-->
<!--                  </div>-->
<!--                </div>-->

<!--                <div class="five wide column">-->
<!--                  <a href="#" target="_blank">-->
<!--                    <img src="https://unsplash.it/800/450?image=1005" alt="" class="ui rounded image">-->
<!--                  </a>-->
<!--                </div>-->

<!--              </div>-->
<!--            </div>-->
            <!--*/-->
          </div>

          <!--footer-->
          <div class="ui bottom attached segment">
            <div class="ui middle aligned two column grid">
              <div class="column">
                <div v-if="preBoolean">
                  <a style="cursor: pointer" @click="toPrePage" class="ui mini teal basic button">上一页</a>
                </div>
              </div>
              <div class="right aligned column">
                <div v-if="nexBoolean">
                  <a style="cursor: pointer" @click="toNextPage" class="ui mini teal basic button">下一页</a>
                </div>
              </div>
            </div>
          </div>

        </div>

        <!--右边的top-->
        <div class="five wide column">

          <!--分类-->
          <div class="ui segments">
            <div class="ui secondary segment">
              <div class="ui two column grid">
                <div class="column">
                  <i class="idea icon"></i>分类
                </div>
                <div class="right aligned column">
                  <a href="/type" target="_blank">more <i class="angle double right icon"></i></a>
                </div>
              </div>
            </div>
            <div class="ui teal segment">
              <div class="ui fluid vertical menu" >
                <a style="cursor:pointer" @click="toType(type.id)" target="_blank" class="item" v-for="type in types">
                  <span>{{type.name}}</span>
                  <div class="ui teal basic left pointing label">{{type.count}}</div>
                </a>
              </div>
            </div>
          </div>

          <!--标签-->
          <div class="ui segments m-margin-top-large">
            <div class="ui secondary segment">
              <div class="ui two column grid">
                <div class="column">
                  <i class="tags icon"></i>标签
                </div>
                <div class="right aligned column">
                  <a href="/tag" target="_blank">more <i class="angle double right icon"></i></a>
                </div>
              </div>
            </div>
            <div class="ui teal segment">
              <a style="cursor:pointer" @click="toTag(tag.id)" target="_blank" class="ui teal basic left pointing label m-margin-tb-tiny" v-for="tag in tags">
                <span>{{tag.name}}</span> <div class="detail">{{tag.count}}</div>
              </a>
            </div>
          </div>

          <!--最新推荐-->
          <div class="ui segments m-margin-top-large">
            <div class="ui secondary segment ">
              <i class="bookmark icon"></i>最新推荐
            </div>
            <div class="ui segment" v-for="blog in blogs">
              <a href="#" target="_blank" class="m-black m-text-thin">{{blog.title}}</a>
            </div>
          </div>

          <!--二维码-->
          <h4 class="ui horizontal divider header m-margin-top-large">扫码关注我</h4>
          <div class="ui centered card" style="width: 11em">
            <img src="../assets/images/wechat.png" alt="" class="ui rounded image" >
          </div>
        </div>

      </div>
    </div>

  </div>

  <br>
  <br>


</template>

<script>
import axios from "axios";

export default {
  name: "Index",
  data(){
    return {
      tags: [],
      types: [],
      blogs: [],
      preBoolean: '',
      nexBoolean: '',
      curPage: '',
      blogCount: ''
    }
  },
  mounted() {
    this.$store.commit('setO1');
    this.getBlogs();
  },
  methods:{
    toTag(id){
      // alert(id);
      this.$store.commit('setActiveTagId',id);
      this.$router.push({path: '/tag'});
    },
    toType(id){
      this.$store.commit('setActiveTypeId',id);
      this.$router.push({path: '/type'});
    },
    toBlog(id){
      this.$store.commit('setBlogId',id);
      this.$router.push({path: '/blog'});
    },
    toPrePage(){
      axios.get('http://localhost:7070/'+"?page="+(this.curPage-1)).then((res)=>{
        this.blogs = res.data.page;
        console.log(this.blogs);
        this.preBoolean = res.data.preBoolean;
        this.types = res.data.types;
        this.curPage = res.data.curPage;
        this.nexBoolean = res.data.nexBoolean;
        this.tags = res.data.tags;
        this.blogCount = res.data.blogCount;
      })
    },
    toNextPage(){
      axios.get('http://localhost:7070/'+"?page="+(this.curPage+1)).then((res)=>{
        this.blogs = res.data.page;
        console.log(this.blogs);
        this.preBoolean = res.data.preBoolean;
        this.types = res.data.types;
        this.curPage = res.data.curPage;
        this.nexBoolean = res.data.nexBoolean;
        this.tags = res.data.tags;
        this.blogCount = res.data.blogCount;
      })
    },
    getBlogs(){
      axios.get('http://localhost:7070').then((res)=>{
        this.blogs = res.data.page;
        console.log(this.blogs);
        this.preBoolean = res.data.preBoolean;
        this.types = res.data.types;
        this.curPage = res.data.curPage;
        this.nexBoolean = res.data.nexBoolean;
        this.tags = res.data.tags;
        console.log(this.tags);
        this.blogCount = res.data.blogCount;
      })
    },
    dateFormat(time) {
      var date=new Date(time);
      var year=date.getFullYear();
      /* 在日期格式中，月份是从0开始的，因此要加0
       * 使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
       * */
      var month= date.getMonth()+1<10 ? "0"+(date.getMonth()+1) : date.getMonth()+1;
      var day=date.getDate()<10 ? "0"+date.getDate() : date.getDate();
      var hours=date.getHours()<10 ? "0"+date.getHours() : date.getHours();
      var minutes=date.getMinutes()<10 ? "0"+date.getMinutes() : date.getMinutes();
      var seconds=date.getSeconds()<10 ? "0"+date.getSeconds() : date.getSeconds();
      // 拼接
      // return year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds;
      return year+"-"+month+"-"+day;
    },
    dateFormat1(time) {
      var date=new Date(time);
      var year=date.getFullYear();
      /* 在日期格式中，月份是从0开始的，因此要加0
       * 使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
       * */
      var month= date.getMonth()+1<10 ? "0"+(date.getMonth()+1) : date.getMonth()+1;
      var day=date.getDate()<10 ? "0"+date.getDate() : date.getDate();
      var hours=date.getHours()<10 ? "0"+date.getHours() : date.getHours();
      var minutes=date.getMinutes()<10 ? "0"+date.getMinutes() : date.getMinutes();
      var seconds=date.getSeconds()<10 ? "0"+date.getSeconds() : date.getSeconds();
      // 拼接
      return year+"-"+month+"-"+day+" "+hours+":"+minutes;
      // return year+"-"+month+"-"+day;
    }
  }
}
</script>

<style scoped>

</style>